unit wnMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Registry;

type
  TfrmMain = class(TForm)
    btnStart: TButton;
    btnCompille: TButton;
    btnAutoStart: TButton;
    btnExit: TButton;
    Bevel1: TBevel;
    Bevel2: TBevel;
    procedure btnExitClick(Sender: TObject);
    procedure btnStartClick(Sender: TObject);
    procedure btnCompilleClick(Sender: TObject);
    procedure btnAutoStartClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

uses wnBuilder;

{$R *.dfm}

procedure TfrmMain.btnAutoStartClick(Sender: TObject);
var
  cmd : string;
  reg : TRegistry;  
begin
  cmd := 'python "' + ExtractFileDir(ExtractFileDir(Application.ExeName)) + '\server\runserver.py' + '"';
  reg := TRegistry.Create;
  reg.RootKey := HKEY_LOCAL_MACHINE;
  reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
  if not reg.ValueExists('RestServer') then
  begin
    reg.WriteString('RestServer', cmd);
  end;
  reg.Free;  
end;

procedure TfrmMain.btnCompilleClick(Sender: TObject);
begin
  with TfrmBuilder.Create(Self) do
  begin
    ShowModal;
    Free;
  end;
end;

procedure TfrmMain.btnExitClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmMain.btnStartClick(Sender: TObject);
var
  cmd : string;
begin
  cmd := 'python "' + ExtractFileDir(ExtractFileDir(Application.ExeName)) + '\server\runserver.py' + '"';
  WinExec(PAnsiChar(AnsiString(cmd)), SW_NORMAL);
  Close;
end;

end.
